Page({
  data: {
    report: null,
    skills: [
      { name: "表达能力", score: 0 },
      { name: "逻辑思维", score: 0 },
      { name: "专业知识", score: 0 },
      { name: "沟通技巧", score: 0 },
      { name: "问题解决", score: 0 }
    ]
  },

  onLoad: function(options) {
    const timestamp = options.timestamp;
    const app = getApp();
    
    // 查找对应的面试记录
    const report = app.globalData.interviewHistory.find(record => record.timestamp === timestamp);
    
    if (report) {
      // 为技能评分
      const baseScore = Math.floor(report.score / 10);
      const skills = this.data.skills.map(skill => {
        // 每个技能随机在基础分上下浮动
        const randomScore = Math.floor(Math.random() * 3) - 1;
        const score = Math.max(0, Math.min(10, baseScore + randomScore));
        return { ...skill, score: score * 10 };
      });
      
      this.setData({
        report: report,
        skills: skills
      });
    }
  },

  // 返回首页
  backToHome: function() {
    wx.switchTab({
      url: '/pages/index/index'
    });
  },

  // 查看面试历史
  viewHistory: function() {
    wx.navigateTo({
      url: '/pages/history/history'
    });
  },

  // 分享报告
  onShareAppMessage: function() {
    return {
      title: '我的面试报告',
      path: `/pages/report/report?timestamp=${this.data.report.timestamp}`,
      success: function(res) {
        wx.showToast({
          title: '分享成功',
          icon: 'success'
        });
      },
      fail: function(res) {
        wx.showToast({
          title: '分享失败',
          icon: 'none'
        });
      }
    };
  }
});
